<!doctype html>
<html class="no-js">
<head>
 <title>源码-TngouFS测试</title>
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
  <meta name="renderer" content="webkit">
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <link rel="icon" type="image/png" href=" ../common/amazeui/i/favicon.png">
  <link rel="apple-touch-icon-precomposed" href=" ../common/amazeui/i/app-icon72x72@2x.png">
  <meta name="apple-mobile-web-app-title" content="Amaze UI" />
  <link rel="stylesheet" href=" ../common/amazeui/css/amazeui.min.css"/>
  <link rel="stylesheet" href=" ../common/amazeui/css/admin.css">
    
  <script type="text/javascript" src=" ../common/js/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src=" ../common/js/jquery.form.min.js"></script>
  
</head>
<body>
<!--[if lte IE 9]>
<p class="browsehappy">你正在使用<strong>过时</strong>的浏览器，TngouFS 暂不支持。 请 <a href="http://browsehappy.com/" target="_blank">升级浏览器</a>
  以获得更好的体验！</p>
<![endif]-->


<header data-am-widget="header" class="am-header  am-header-default am-no-layout" style="border-bottom:1px solid #e7e7e7;background: #f9f9f9;">
 
  <div class="am-header-left am-header-nav" style="margin-left:12rem;">
   <ol class="am-breadcrumb">
  <li><a href="index.html">首页</a></li>
  <li><a href="ueditor.html">UEditor功能</a></li>
  <li><a href="urlext.html">URL提取</a></li>
  <li><a href="urlload.html">URL下载</a></li>
  <li><a href="imgup.html">图片上传</a></li>
    <li><a href="imgsearch.html">图片搜索</a></li>
    <li><a href="show.html">图片展示</a></li>
        <li><a href="source.html">源码</a></li>


</ol>

  </div>
  <div class="am-header-right am-header-nav" >
  	 <a href="../" class="am-btn am-btn-warning">最新图片
	    <i class="am-header-icon"></i>
	 </a>
   

	 <a href=" ../login" class="am-btn am-btn-primary">登录
	    
	 </a>

   
   
    <a href="http://www.tngou.net/doc/gallery" class="am-btn am-btn-secondary" target="_blank">API开放接口
	  
	 </a>
	 
	  <a href="http://www.tngou.net/doc/tnfs" class="am-btn am-btn-success" target="_blank">网站源码
	  
	 </a>
  </div>
</header>



<div class="am-container">

<hr>
<div ><h2><span>ControllerAction</span></h2>

<pre>
	@Override
	public void execute() throws ServletException, IOException {	
		//转换直接调用的是百度的后台接口
		printJson(new ActionEnter( request ).exec()); 	
		
	}
	
	
	/**
	 * 图片搜索
	 */
	public void imgsearch()  {		
				String q=request.getParameter("q");  //关键词
				String path=request.getParameter("path");
				if(StringUtils.isEmpty(path))path=File.separator+"default"+File.separator;
				String name=request.getParameter("name");  //
				String title=request.getParameter("title");  //
				if(StringUtils.isEmpty(title))title=q;
				String message=request.getParameter("message");  //
				if(StringUtils.isEmpty(message))message=q;
				String tag=request.getParameter("tag");  //
				List<String> urls = new Img4s().getImgUrl(q);				
				if(urls.size()==0)
				{
					String json="{\"code\":404}";//错误
					printJson(json);
					return ;
				}				
				String imgurl=urls.get(0);					
				if(!path.startsWith(File.separator))path=File.separator+path;
				if(!path.endsWith(File.separator))path=path+File.separator;
				HttpConfig httpConfig = HttpConfig.getInstance();
				String savePath =httpConfig.getTnfspath()+File.separator+"img"+path;
				String saveUrl = path;
				String url = ImgUtil.DownImg(imgurl, savePath, saveUrl,name);
//				ImgService imgService = new ImgService();
//				imgService.saveDB(url, q, q, tag);
				String json="{\"code\":404}";//错误
				if(url!=null)
				{
					/**
					 * code 200 返回成功
					 * url ：图片URL简略地址
					 * fullurl：图片URL完整地址
					 * path ：图片服务器地址
					 */
					json="{\"code\":200,\"url\":\""+PathFormat.format(url)+"\",\"fullurl\":\""+httpConfig.getImgurl()+PathFormat.format(url)+"\",\"tnfs\":\""+httpConfig.getTnfsurl()+"\"}";
				}			
				printJson(json);
	}
	
	
	/**
	 * 图片下载
	 */
	public void imgdownload() {
		
				String imgurl=request.getParameter("imgurl");  //鍥剧墖URL
				String name=request.getParameter("name");  //
				String path=request.getParameter("path");
				if(StringUtils.isEmpty(path))path=File.separator+"default"+File.separator;
				String title=request.getParameter("title");  //
				String message=request.getParameter("message");  //
				String tag=request.getParameter("tag");  //
				if(!path.startsWith(File.separator))path=File.separator+path;
				if(!path.endsWith(File.separator))path=path+File.separator;
				HttpConfig httpConfig = HttpConfig.getInstance();
				String savePath =httpConfig.getTnfspath()+File.separator+"img"+path;
				String saveUrl = path;							
				String url = ImgUtil.DownImg(imgurl, savePath, saveUrl,name);				
//				ImgService imgService = new ImgService();
//				imgService.saveDB(url, title, message, tag);				
				String json="{\"code\":404}";//错误
				if(url!=null)
				{
					/**
					 * code 200 返回成功
					 * url ：图片URL简略地址
					 * fullurl：图片URL完整地址
					 * path ：图片服务器地址
					 */
					json="{\"code\":200,\"url\":\""+PathFormat.format(url)+"\",\"fullurl\":\""+httpConfig.getImgurl()+PathFormat.format(url)+"\",\"tnfs\":\""+httpConfig.getTnfsurl()+"\"}";
				}
				
				printJson(json);
	}
	
	/*
	* 图片剪切
	*/
	public void imgcut() {
    	int startX =request.getParameter("startX")==null?0:Integer.parseInt(request.getParameter("startX"));
        int startY = request.getParameter("startY")==null?0:Integer.parseInt(request.getParameter("startY"));
        int endX = request.getParameter("endX")==null?0:Integer.parseInt(request.getParameter("endX"));
        int endY =request.getParameter("endY")==null?0:Integer.parseInt(request.getParameter("endY"));
        int size =request.getParameter("size")==null?200:Integer.parseInt(request.getParameter("size"));
        String contextPath=request.getParameter("path");
        if(StringUtils.isEmpty(contextPath))contextPath=File.separator+"default";
        if(!contextPath.startsWith(File.separator))contextPath=File.separator+contextPath; //File.separator =windows是\，unix是/	
        String name=request.getParameter("name");
        if(StringUtils.isEmpty(name))name=File.separator+new Date().hashCode();
        if(!name.startsWith(File.separator))name=File.separator+name; //File.separator =windows是\，unix是/	
        String src = request.getParameter("src");
        HttpConfig httpConfig = HttpConfig.getInstance();
        src=StringUtils.remove(src, httpConfig.getImgurl());        
        src=StringUtils.replace(src, "/", File.separator);
        src=File.separator+"img"+src;
        src=httpConfig.getTnfspath()+src;     
        ImgTool imgTool = new ImgTool();
        BufferedImage bufferedImage = imgTool.image(src);
        if(endX==0)endX=bufferedImage.getWidth();
        if(endY==0)endY=bufferedImage.getHeight();
        bufferedImage=imgTool.crop(bufferedImage, startX, startY, endX, endY);       
        bufferedImage= imgTool.crop(bufferedImage, size, size,true); //等比压缩           
        DateTimeFormatter f = DateTimeFormatter.ofPattern("yyMMdd");
		LocalDate date =LocalDate.now();
        String ymd = date.format(f);
        String pathname=contextPath+File.separator+ymd+name+".png";
        String savename=httpConfig.getTnfspath()+File.separator+"img"+pathname;
		File file = new File(savename);
		file=imgTool.save(bufferedImage, file );		
		String json="{\"code\":404}";//错误
		if(file.isFile())
		{
			/**
			 * code 200 返回成功
			 * url ：图片URL简略地址
			 * fullurl：图片URL完整地址
			 * path ：图片服务器地址
			 */
			String url=pathname;
			json="{\"code\":200,\"url\":\""+PathFormat.format(url)+"\",\"fullurl\":\""+httpConfig.getImgurl()+PathFormat.format(url)+"\",\"tnfs\":\""+httpConfig.getTnfsurl()+"\"}";
//		    new File(src).delete();
		
		}
		
		printJson(json);
	}
	

</pre>




</div>




<hr>
<div ><h2><span>ImageAction</span></h2>

<pre>
	/**
	 *   http://tnfs.tngou.net/image/news/150101/1.jpg_200x200[_oc|fc|tc]
	 *   oc:省略剪切
	 *   fc 填充剪切 
	 *   tc ：透明剪切
	 *   如果是   0x200 就指 高度为200宽度任意（等比例压缩）
	 *   如果是  200x0 就指  宽度为200高度度任意 （等比例压缩）
	 */
	@Override
	public void execute() throws ServletException, IOException {
		
		Img  img=_getImg();
		if(img.getWidth()<0||img.getHeight()<0) // 宽度限制
		{
			run_404();
			return;
		}
		HttpConfig httpConfig = HttpConfig.getInstance();
		if((img.getWidth()<httpConfig.getMinwidth()&&img.getWidth()!=0)||(img.getHeight()<httpConfig.getMinheight()&&img.getHeight()!=0)) //最小比例
		{
			    //最小宽度，高度限制 0x0除外	
				run_404();
				return;
			
		}
		if(img.getWidth()>httpConfig.getMaxwidth()||img.getHeight()>httpConfig.getMaxheight()) //最大比例
		{
			//最大宽度，高度限制
			run_404();
			return;
		}
		String rootPath = HttpConfig.getInstance().getTnfspath()+File.separator+"img";
		File imgfile = new File(rootPath+img.getSrc());
		if(!imgfile.isFile())
		{
			run_404();
			return;
		}
		String temp= HttpConfig.getInstance().getTnfspath()+File.separator+"temp"+File.separator+"image";
		File tempFile = new File(temp+img.getTemp()); 
		if(img.getWidth()>0&&img.getHeight()>0)
		{			
			if(!tempFile.isFile())
			{
			   ImgTool imgTool = new ImgTool();
			   
			   BufferedImage bufferedImage = null;
			   switch (img.getCuttype()) {
				case "oc": //oc:省略剪切
					bufferedImage =imgTool.crop(imgTool.image(imgfile), img.getWidth(), img.getHeight());
					break;
				case "fc":// fc 填充剪切 
					bufferedImage = imgTool.crop(imgTool.image(imgfile), img.getWidth(), img.getHeight(),false);
					break;
				case "tc":// tc ：透明剪切
					bufferedImage = imgTool.crop(imgTool.image(imgfile), img.getWidth(), img.getHeight(),true);
					break;
				default:// 默认透明剪切
					bufferedImage = imgTool.crop(imgTool.image(imgfile), img.getWidth(), img.getHeight(),true);
					break;
				}
	   
			   if(!tempFile.getParentFile().isDirectory())
			   {
				   tempFile.getParentFile().mkdirs();
			   }
			   imgfile=imgTool.save(bufferedImage, tempFile);
			}else
			{
				imgfile=tempFile;
				
			}
		}
		else if(img.getWidth()*img.getHeight()==0&&(img.getWidth()>0||img.getHeight()>0)) //如果有一边 为 0 
		{
			if(!tempFile.isFile())
			{
				ImgTool imgTool = new ImgTool();
				BufferedImage bufferedImage = imgTool.resize(imgTool.image(imgfile), img.getWidth(), img.getHeight());
				if(!tempFile.getParentFile().isDirectory())
				   {
					   tempFile.getParentFile().mkdirs();
				   }
				   imgfile=imgTool.save(bufferedImage, tempFile);
			}
			else
			{
				imgfile=tempFile;			
			}
		}
		else{	
			if(!tempFile.isFile())
			{
				FileUtils.copyFile(imgfile, tempFile);
			}
		}
	printImg(imgfile);		
	}	
</pre>




</div>


</div>




<footer data-am-widget="footer" class="am-footer am-footer-default am-no-layout">
  <div class="am-footer-switch">
    <div id="godesktop" data-rel="desktop" class="am-footer-desktop">天狗-TngouFS图片</div>
  </div>
  <div class="am-footer-miscs ">
    <p>本站非盈利，网站数据全部来源于网络，只为测试网速使用，以及TngouFS文件系统，如果有相关侵权或违法法律请联系
      <a href="http://www.tngou.net" title="天狗网" target="_blank" class="">天狗网</a> 会对相应的数据进行清理！</p>
    <p>CopyRight©2015 Tngou.NET</p>
  </div>
</footer>

<!--[if lt IE 9]>

<script src=" ../common/amazeui/js/modernizr.js"></script>
<script src=" ../common/amazeui/js/amazeui.ie8polyfill.min.js"></script>
<![endif]-->

<!--[if (gte IE 9)|!(IE)]><!-->
<!--<![endif]-->
<script src=" ../common/amazeui/js/amazeui.min.js"></script>
<script src=" ../common/amazeui/js/app.js"></script>
</body>
</html>